<template>
	<view :style="{'padding-bottom':showAudit?'180rpx':'20rpx'}"> 
		<view class="flex justify-center align-center py-3">
			<u--image v-if="obj.status==1" src="/static/images/ui/salary/wait.png" width="148rpx" height="148rpx"></u--image>
			<u--image v-if="obj.status==2" src="/static/images/ui/salary/pass.png" width="148rpx" height="148rpx"></u--image>
			<u--image v-if="obj.status==3" src="/static/images/ui/salary/unpass.png" width="148rpx" height="148rpx"></u--image>
		</view>
		<view class="px-3">
			<view class="bt-block">
				<bg-cell2 label="姓名" :value="obj.createUserName" valueColor="#4e5969"></bg-cell2>
				<bg-cell2 label="身份证号" :value="obj.idCardNo" valueColor="#4e5969"></bg-cell2>
				<bg-cell2 :border="false" label="手机号" :value="obj.phone" value-color="#4e5969"></bg-cell2>
			</view>
			<view class="bt-block my-3">
				<bg-title class="margin-top mx-3">
					<text class="font-1">借支申请单</text>
				</bg-title>
				<bg-cell2 label="项目名称" :value="obj.projectName" valueColor="#4e5969"></bg-cell2>
				<bg-cell2 label="借支金额" :value="obj.amount" valueColor="#4e5969"></bg-cell2>
				<bg-cell2 label="卡号" :value="obj.bankCardNo" valueColor="#4e5969"></bg-cell2>
				<bg-cell2 :border="false" label="开户行" :value="obj.bankName" valueColor="#4e5969"></bg-cell2>
			</view>
			<view class="bt-block my-3">
				<bg-title class="margin-top mx-3">
					<text class="font-1">本人确认签字</text>
				</bg-title>
				<view class="p-3">
					<u--image width="380rpx" height="154rpx" mode="widthFix"  :src="obj.signedImg"></u--image>
				</view>
			</view>
			<view class="bt-block my-3">
				<bg-title class="margin-top mx-3">
					<text class="font-1">流程节点图</text>
				</bg-title>
				<view class="p-3">
					<bg-step :list="authList"></bg-step>
				</view>
			</view> 
		</view>
		<view class="bt-footer bt-gap" v-if="isShow">
			<bg-btn plain @click="reject">审批未通过</bg-btn>
			<bg-btn @click="confirm">审批通过</bg-btn>
		</view>
		
	</view>
</template>

<script>
	import {borrowDetail, borrowLeaderAudit, borrowManagerAudit} from "@/api/salary.js"
	export default {
		data() {
			return {
				authList:[],
				id:'',
				showAudit:false,
				obj:{},
			}
		},
		onLoad(options) {
			this.id = options.id
			this.showAudit = options.show?true:false
			this.getDetail()
		},
		computed:{
			isShow(){
				return this.showAudit&&this.obj.status==1&&this.obj.auditUserId==this.$store.getters.userId
			}
		},
		methods: {
			starNo(str){
				if(str){
					return str.replace(/(?<=\d{4})\d+(?=\d{4})/,"****");
				}else{
					return ""
				}
			},
			getDetail(){
				borrowDetail(this.id).then(res=>{
					this.obj = res.data
					this.obj.bankCardNo = this.starNo(this.obj.bankCardNo)
					this.authList = [
						{auditUserName:this.obj.createUserName, auditTime:this.obj.createTime},
						...this.obj.auditRecordList
					]
				})
			},
			confirm(){
				//todo 怎么判断leader 和 manager
				let method = null
				if(this.$auth.hasRole("team")){
					method = borrowLeaderAudit
				}
				if(this.$auth.hasRole("project")){
					method = borrowManagerAudit
				}
				if(!method){
					this.$modal.msg("您当前暂无权限")
					return false
				}
				method({id:this.obj.id, status:"2"}).then(res=>{
					this.$modal.msgSuccess("审批成功")
					uni.$emit("refresh-borrow", true)
					this.$tab.navigateBackDelay()
				})
			},
			reject(){
				let method = null
				if(this.$auth.hasRole("team")){
					method = borrowLeaderAudit
				}
				if(this.$auth.hasRole("project")){
					method = borrowManagerAudit
				}
				if(!method){
					this.$modal.msg("您当前暂无权限")
					return false
				}
				method({id:this.obj.id, status:"3"}).then(res=>{
					this.$modal.msgSuccess("审批成功")
					uni.$emit("refresh-borrow", true)
					this.$tab.navigateBackDelay()
				})
			}
		}
	}
</script>

<style>

</style>
